#include "IdentTable.hpp"



IdentTable::IdentTable(){
	mCpt = 0;
}
IdentTable::~IdentTable(){
}
int IdentTable::tempCpt = 0;

void IdentTable::afficher(){
	cout << "** Table identificateurs" << endl;
	map<string,int>::iterator it;
	for ( it=mIds.begin() ; it != mIds.end(); it++ ){
    	cout << (*it).first << " " << (*it).second << endl;
	}
	cout << endl << endl;
}
void IdentTable::ajouter(string value){
	mIds.insert ( pair<string,int>(value,mCpt) );
	mCpt++;			
}
int IdentTable::ajouterTemporaire(){
	string nomTemp;
	int mCptPrec=this->mCpt;
	stringstream sstm;
	
	sstm << "t" << IdentTable::tempCpt;
	nomTemp = sstm.str();	
	mIds.insert ( pair<string,int>(nomTemp,mCpt) );
	mCpt++;
	IdentTable::tempCpt++;
	
	return mCptPrec;	
}

int IdentTable::getID(string value){
	map<string,int>::iterator it;	
	it = mIds.find(value);
	return (*it).second;
}
char * IdentTable::getName(int id){
	map<string,int>::iterator it;
	for ( it=mIds.begin() ; it != mIds.end(); it++ ){
		if((*it).second == id){
			size_t size = (*it).first.size() + 1;
	   		char * buffer = new char[ size ];
			strncpy( buffer, (*it).first.c_str(), size );
			return buffer;	
		}
	}
return 0;
}

